<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />

<atleap:isUserInRole roles="core-contentField-create, core-contentField-override, core-contentField-createIndexed" var="canCreateSome" />
<atleap:isUserInRole roles="core-contentField-update, core-contentField-updateOverriden, core-contentField-updateIndexed" var="canUpdateSome" />
<atleap:isUserInRole roles="core-contentField-update" var="canUpdate" />
<atleap:isUserInRole roles="core-contentField-updateOverriden" var="canUpdateOverriden" />
<atleap:isUserInRole roles="core-contentField-updateIndexed" var="canUpdateIndexed" />
<atleap:isUserInRole roles="core-contentField-view" var="canView" />
<atleap:isUserInRole roles="core-contentField-delete, core-contentField-deleteOverriden, core-contentField-deleteIndexed" var="canDeleteSome" />
<atleap:isUserInRole roles="core-contentField-delete" var="canDelete" />
<atleap:isUserInRole roles="core-contentField-deleteOverriden" var="canDeleteOverriden" />
<atleap:isUserInRole roles="core-contentField-deleteIndexed" var="canDeleteIndexed" />

<c:set var="infoCells" value="2" />
<c:set var="constantButtonCells" value="0" />
<c:set var="additionalCells" value="0" />
<c:if test="${canUpdateSome && requestScope.canCreateOrUpdate != null}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canView}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canDeleteSome}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>

<atleap:content identifier="cfListInfo" ignore="true" />
<atleap:grid name="contentFieldGrid" pageSize="${pageSize}">
	<atleap:messages property="contentFieldNotFound" />
	<atleap:messages property="contentFieldCannotDelete" />
	<atleap:messages property="cantCreateOrUpdate" />
    <atleap:queryParameter name="ownerId" value="${requestScope.ownerId}" />
    <table border="0" cellpadding="0" cellspacing="0" class="grid">
        <thead>
            <tr>
                <th nowrap="nowrap">
                    <atleap:column fieldName="f.identifier" fieldKey="core.contentField.form.identifier">
                        <atleap:sort>
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                        </atleap:sort>
                        <atleap:stringFilter>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                        </atleap:stringFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:column fieldName="f.type" fieldKey="core.contentField.form.type">
                        <atleap:sort>
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                            </atleap:sort>
                    </atleap:column>
                </th>
                <c:if test="${constantButtonCells + additionalCells > 0}">
                    <th colspan="${constantButtonCells + additionalCells}">
                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                    </th>
                </c:if>
             </tr>
        </thead>
        <tbody>
        	<atleap:contextMenu var="menuId">
				<atleap:rowsIterator beanId="contentFieldManager" method="listContentFields" var="contentField" oddClass="oddRow" evenClass="evenRow">
					<atleap:itemSet>
						<c:set var="updateAllowed" value="${canUpdate || (canUpdateOverriden && requestScope.ownerIsCP != null) || (canUpdateOverriden && requestScope.ownerIsAP != null && requestScope.overridenAPFields[contentField.identifier]) || (canUpdateIndexed && requestScope.ownerIsLayout != null && ((contentField.index != null && contentField.index> 0) || requestScope.overridenLayoutFields[contentField.identifier]) ) }" />
						<c:set var="deleteAllowed" value="${canDelete || (canDeleteOverriden && requestScope.ownerIsCP != null) || (canDeleteOverriden && requestScope.ownerIsAP != null && requestScope.overridenAPFields[contentField.identifier]) || (canDeleteIndexed && requestScope.ownerIsLayout != null && ((contentField.index != null && contentField.index> 0) || requestScope.overridenLayoutFields[contentField.identifier]) ) }" />
                        <atleap:rewriteUrl action="core/contentField/view?ownerId=${requestScope.ownerId}" var="defaultUrl">
                            <atleap:param name="id" value="${contentField.id}" />
                        </atleap:rewriteUrl>
                        <c:set var="onTrClickCode" value="" />
                        <c:set var="tdClass" value="defaultCursorCell" />
                        <c:if test="${canView}">
                            <c:set var="onTrClickCode" value="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);" />
                            <c:set var="tdClass" value="pointerCursorCell" />
                        </c:if>
						<tr class="${rowClass}" oncontextmenu="return showContextMenu(${menuId}, event, ${indexId});" onclick="${onTrClickCode}">
							<td class="${tdClass}"><c:out value="${contentField.identifier}" escapeXml="true" /></td>
							<td class="${tdClass}"><atleap:message key="core.contentField.form.type.${contentField.type}" /></td>
							<c:set var="showItem" value="${canUpdateSome && requestScope.canCreateOrUpdate != null}" />
							<atleap:item enabled="${updateAllowed}" includeInContextMenu="${showItem}" includeInPage="${showItem}">
                                <atleap:message key="core.commons.buttons.callUpdate" var="callUpdateMsg" />
								<td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
									<atleap:itemEnabled>

										<atleap:itemLink action="core/contentField/callUpdate?ownerId=${requestScope.ownerId}" title="${callUpdateMsg}">
											<atleap:param name="id" value="${contentField.id}" />
                                            
                                                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/edit.gif" />" border="0" title="${callUpdateMsg}" alt="${callUpdateMsg}"  align="absmiddle" />
                                                    <atleap:itemLabel>
                                                        ${callUpdateMsg}
                                                    </atleap:itemLabel>
										</atleap:itemLink>
									</atleap:itemEnabled>
									<atleap:itemDisabled>
                                        <atleap:message key="core.contentField.form.editDisabled" var="editDisabledMsg" />
                                        <atleap:itemLink title="${editDisabledMsg}">

                                                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/editDisabled.gif" />" border="0" alt="${editDisabledMsg}" title="${editDisabledMsg}"  align="absmiddle" />
                                                    <atleap:itemLabel>
                                                        ${callUpdateMsg}
                                                    </atleap:itemLabel>
                                        </atleap:itemLink>
									</atleap:itemDisabled>
								</td>
							</atleap:item>
							<atleap:item includeInContextMenu="${canView}" includeInPage="${canView}">
								<td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
									<atleap:itemEnabled>
										<atleap:message key="core.commons.buttons.view" var="viewMsg"/>
										<atleap:itemLink action="core/contentField/view?ownerId=${requestScope.ownerId}" title="${viewMsg}">
											<atleap:param name="id" value="${contentField.id}" />

                                                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/view.gif" />" border="0" title="${viewMsg}" alt="${viewMsg}"  align="absmiddle" />
                                                    <atleap:itemLabel>
                                                        ${viewMsg}
                                                    </atleap:itemLabel>
										</atleap:itemLink>
									</atleap:itemEnabled>
								</td>
							</atleap:item>
                            <c:set var="showItem" value="${canDeleteSome}" />
							<atleap:item enabled="${deleteAllowed}" includeInContextMenu="${showItem}" includeInPage="${showItem}">
								<td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
									<atleap:message key="core.commons.buttons.delete" var="deleteMsg"/>
									<atleap:itemEnabled>
										<atleap:itemLink action="core/contentField/delete?ownerId=${requestScope.ownerId}" transaction="true" confirmExpression="confirmDelete();" title="${deleteMsg}">
											<atleap:param name="id" value="${contentField.id}" />

                                                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/delete.gif" />" border="0" title="${deleteMsg}" alt="${deleteMsg}" align="absmiddle" />
                                                    <atleap:itemLabel>
                                                        ${deleteMsg}
                                                    </atleap:itemLabel>
										</atleap:itemLink>
									</atleap:itemEnabled>
									<atleap:itemDisabled>
										<atleap:message key="core.contentField.form.deleteDisabled" var="deleteDisabledMsg" />
                                        <atleap:itemLink title="${deleteDisabledMsg}">

                                                    <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/deleteDisabled.gif" />" border="0" alt="${deleteDisabledMsg}" title="${deleteDisabledMsg}"  align="absmiddle" />
                                                    <atleap:itemLabel>
                                                        ${deleteMsg}
                                                    </atleap:itemLabel>
                                        </atleap:itemLink>
									</atleap:itemDisabled>
								</td>
							</atleap:item>
						</tr>
					</atleap:itemSet>
				</atleap:rowsIterator>
            </atleap:contextMenu>
            <atleap:noRows>
                <tr>
                    <td class="tfoot" colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <em><atleap:message key="core.commons.nothingToShow"/></em>
                    </td>
                </tr>
            </atleap:noRows>
        </tbody>
        <tfoot>
            <tr>
                <atleap:pager pageCount="10">
                    <td colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <atleap:message key="core.grid.pager.title" />&nbsp;
                        <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                        <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                        <atleap:pagesIterator>
                            <atleap:page>${pageNumber}&nbsp;</atleap:page>
                            <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                        </atleap:pagesIterator>
                        <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                        <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                    </td>
                </atleap:pager>
            </tr>
        </tfoot>
    </table>
    <c:if test="${canCreateSome && requestScope.canCreateOrUpdate != null}">
		<atleap:form action="core/contentField/callCreate" method="GET" validateOnSubmit="false">
			<html:hidden property="ownerId" value="${requestScope.ownerId}" />
			<atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.create" /></atleap:submit>
		</atleap:form>
    </c:if>
</atleap:grid>
